package com.zscat.mallplus.controller;

import com.zscat.mallplus.feedback.entity.FeedBack;
import com.zscat.mallplus.service.FeedBackService;
import com.zscat.mallplus.pay.utils.StringUtils;
import com.zscat.mallplus.ums.entity.UmsMember;
import com.zscat.mallplus.ums.service.IUmsMemberService;
import com.zscat.mallplus.utils.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 意见反馈
 *
 * @author king.wyx@qq.com
 * @date 2020-09-03
 */
@Slf4j
@RestController
@RequestMapping("/api/feedBack")
public class FeedBackController {
    @Autowired
    private FeedBackService feedBackService;
    @Autowired
    private IUmsMemberService memberService;

    /**
     * 添加意见反馈
     * @param content
     * @param img
     * @return
     */
    @PostMapping("/addFeedBack")
    private CommonResult addFeedBack(String content, String img) {
        if (StringUtils.isEmpty(content) && StringUtils.isEmpty(img)) {
            return new CommonResult().failed("请先填写反馈");
        }
        FeedBack feedBack = new FeedBack();
        feedBack.setContent(content);
        feedBack.setImg(img);
        feedBack.setCreatTime(new Date());
        UmsMember member = memberService.getNewCurrentMember();
        feedBack.setUserId(member.getId());
        feedBack.setNickName(member.getNickname());
        feedBack.setPhone(member.getPhone());
        feedBackService.save(feedBack);
        return new CommonResult().success();
    }
}
